package com.example.lifecycledemo;

import android.app.Activity;
import android.util.Log;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent;

/**
 * Created by xiuzhizhu
 * Date: 2020/11/29
 */

public class MyLocationListener implements LifecycleObserver {

    private static final String TAG = "MyLocationListener";

    public MyLocationListener(LifecycleOwner activity, OnLocationChangedListener onLocationChangedListener) {
        // 初始化
        initLocationManager();
    }

    // 当 Activity 执行 onResume 方法时，自动调用该方法
    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    private void startGetLocation(){
        Log.i(TAG, "startGetLocation() is executed");
    }

    // 当 Activity 执行 onPause 方法时，自动调用该方法
    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    private void stopGetLocation(){
        Log.i(TAG, "stopGetLocation() is executed");
    }

    private void initLocationManager(){
        Log.i(TAG, "initLocationManager() is executed");
    }

    // 当位置发生变化时，通过该接口通知调用方
    public interface OnLocationChangedListener{
        void onChange(double latitude, double longitude);
    }
}
